<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form action="/login/" method="post">
        {% csrf_token %}
        <input type="text" name="user">
        <input type="text" name="pwd">
        <input type="checkbox" name="rmb" value="1">10秒免登录
        <input type="submit" value="提交">
        <input id="btn1" type="button" value="按钮1">
        <input id="btn2" type="button" value="按钮2">
    </form>

    <script src="/static/jquery-1.12.4.js"></script>
    <script src="/static/jquery.cookie.js"></script>
    <script>
        $(function () {
            {#$.cookie('csrftoken');#}
            function csrfSafeMethod(method) {
                // these HTTP methods do not require CSRF protection
                return (/^(GET|HEAD|OPTIONSS|TRACE)$/.test(method));
            }
            $.ajaxSetup({
                beforeSend: function (xhr, settings) {
                    if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                        xhr.setRequestHeader('X-CSRFtoken', $.cookie('csrftoken'))
                    }
                }
        });
            $('#btn1').click(function () {
                $.ajax({
                    url: '/login/',
                    type: 'POST',
                    data: {'user':'root','pwd':'123'},
                    {#headers: {'X-CSRFtoken':$.cookie('csrftoken')},#}
                    success: function (arg) {

                    }
                })
            });
            $('#btn2').click(function () {
                $.ajax({
                    url: '/login/',
                    type: 'POST',
                    data: {'user':'root','pwd':'123'},
                    headers: {'kdfjkd':'1232323'},
                    {#headers: {'X-CSRFtoken':$.cookie('csrftoken')},#}
                    success: function (arg) {
                        location.reload()
                    }
                })
            });
        })
    </script>
</body>
</html>